<script>
	import {
		mapActions,
		mapGetters,
		mapMutations
	} from 'vuex'
	import {
		apiDistributionCode
	} from '@/api/user'
	import {
		strToParams
	} from '@/utils/tools'
	import {
		INVITE_CODE
	} from '@/config/cachekey'
	import Cache from '@/utils/cache'
	export default {
	
		async onLaunch(options) {

			//         // 获取公共配置
			//         await this.getConfig().then(res => {

			//             // 当后台配置商城停止后相关商城进行跳转到空页面
			//             // #ifdef H5
			//             if(!res.h5_status) {
			//                 setTimeout(() => {
			//                     uni.navigateTo({
			//                         url: '/bundle/pages/business_suspended/business_suspended'
			//                     })
			//                 }, 0)
			//             }
			//             // #endif
			//             // #ifdef MP-WEIXIN
			//             if(!res.mnp_status) {
			//                 setTimeout(() => {
			//                     uni.navigateTo({
			//                         url: '/bundle/pages/business_suspended/business_suspended'
			//                     })
			//                 }, 0)
			//             }
			//             // #endif
			//         })
			//         // 获取主题配置
			//         await this.getDecorateConfig()
			//         // 获取个人信息
			//         this.getUser().then((res) => {
			// this.$store.dispatch('getCartNum')
			//             if (this.bindMobile && !res.mobile) {
			//                 this.logout()
			//             }
			//         })

		},
		onShow: function(options) {
			// this.bindCode(options)
			// console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		computed: {
			bindMobile() {
				// 强制绑定手机号
				return this.appConfig.coerce_mobile
			}
		},
		mounted() {
			// #ifdef H5
			this.isWeChat()
			// #endif
		},
		methods: {
			...mapActions([
				'getConfig',
				'getAllDict',
				'getDecorateConfig',
				'getUser',
			]),
			...mapMutations(['logout']),
			async bindCode(options) {
				if (!options.query) return
				let invite_code = options.query.invite_code || strToParams(decodeURIComponent(options.query.scene))
					.invite_code
				console.log(options)
				if (invite_code) {
					apiDistributionCode({
						code: invite_code,
						hide: 1
					}).catch(() => {
						Cache.set(INVITE_CODE, invite_code)
					})
				}
			},
			
			isWeChat: function() {
				let ua = window.navigator.userAgent.toLowerCase()
				if (ua.match(/MicroMessenger/i) == 'micromessenger') { //判断微信浏览器
					let style = document.createElement('style');
					style.type = 'text/css';
					style.innerHTML = "uni-page-head,.uni-page-head{display:none;}";
					document.getElementsByTagName('head').item(0).appendChild(style);
				}
			},
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import 'plugin/emoji-awesome/css/apple.css';
	@import 'styles/common.scss';
	@import "components/uview-ui/index.scss";
	@import "components/uview-ui/theme.scss";

	page {
		background-color: #fafafa;
	}
</style>